import {
	mapGetters,
	mapMutations
} from 'vuex';

export default {
	data() {
		return {
			navPadding: getApp().globalData.statusBarHeight + 50
		};
	},
	computed: {
		...mapGetters(['currentOrg', 'currentUser', 'dossier', 'archivesConfig', 'currentOrgList', 'currentHistoryList',
			'currentHistoryCompanyInfo', 'isSpcePro'
		])
	},
	methods: {
		...mapMutations([
			'setCurrentOrg',
			'setCurrentUser',
			'setDossier',
			'setArchivesConfig',
			'setCurrentOrgList',
			'setCurrentHistoryList',
			'setCurrentHistoryCompanyInfo',
			'cleanAll'
		]),
		getIds: function(__list) {
			let idArr = [];
			__list.forEach(__item => {
				idArr.push(__item.id);
			});
			return idArr.join(',');
		},
		checkPermission(__permissionId) {
			return true;
			// if (!__permissionId) return true;
			// let checked = false;
			// this.currentUser.permissionIdList.forEach(__item => {
			// 	if (__permissionId === __item.id) {
			// 		checked = true;
			// 	}
			// });
			// return checked;
		},
		//获取月初到月末
		getMonthStartAndEnd(e, __str) {
			let date = e ? new Date(e) : new Date()
			const startDatetime = date;
			date.setMonth(date.getMonth() + 1);
			const endDate = date;
			endDate.setDate(0);
			return {
				startDatetime: __str === 'date' ? this.$DateFormat(startDatetime, 'yyyy-MM') + '-01' : this.$DateFormat(
					startDatetime, 'yyyy-MM') + '-01 00:00:00',
				endDatetime: __str === 'date' ? this.$DateFormat(startDatetime, 'yyyy-MM-dd') : this.$DateFormat(
					endDate, 'yyyy-MM-dd') + ' 23:59:59'
			}
		},
		//获取多少天前后的时间（前-，后+）
		getDayTimeAround(__day = 0, __str) {
			let now = new Date();
			let nowTime = now.setDate(now.getDate() + __day);
			let start, end;
			if (__str === 'datetime' || !__str) {
				end = this.$DateFormat(new Date(), 'yyyy-MM-dd') + ' 23:59:59';
				start = this.$DateFormat(nowTime, 'yyyy-MM-dd') + ' 00:00:00';
			} else if (__str === 'date') {
				end = this.$DateFormat(new Date(), 'yyyy-MM-dd');
				start = this.$DateFormat(nowTime, 'yyyy-MM-dd');
			}
			return [start, end];
		},
		moduleValid(__list) {
			let result = false;
			let menuIds = this.currentUser.menuIds;
			__list.forEach(__menuId => {
				if (menuIds.indexOf(__menuId) > -1) {
					result = true;
				}
			});
			return result;
		},
		urlToObj(url) {
			let obj = {}
			let str = url.slice(url.indexOf('?') + 1)
			let arr = str.split('&')
			for (let j = arr.length, i = 0; i < j; i++) {
				let arr_temp = arr[i].split('=')
				obj[arr_temp[0]] = arr_temp[1]
			}
			return obj
		}
	}
}
